package org.gcb.core.ui.nodes;

import java.lang.reflect.InvocationTargetException;
import org.gcb.core.model.Skill;
import org.gcb.core.model.Toon;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;

/**
 *
 * @author Jason
 */
public class SkillNode extends AbstractNode{
    private Skill skill;

    private SkillNode(Skill skill) {
        super(null);
        this.skill = skill;
        setName(skill.getText());
    }

    public static AbstractNode skills(Toon toon) {
        AbstractNode n = new AbstractNode(Children.create(new SkillChildFactory(toon.getSkills()), true));
        n.setName("Root");
        return n;
    }

    @Override
    protected Sheet createSheet() {
        Sheet s = super.createSheet();
        Sheet.Set ss = s.get(Sheet.PROPERTIES);
        if (ss == null) {
            ss = Sheet.createPropertiesSet();
            s.put(ss);
        }
        ss.put(new ArmorPenaltyProperty(skill));
        return super.createSheet();
    }

    private class ArmorPenaltyProperty extends PropertySupport.ReadOnly<Boolean> {
        Skill skill;

        public ArmorPenaltyProperty(Skill skill) {
            super(Skill.PROP_TRAINED, Boolean.class, "Armor Penalty", "Heavy Metal");
            this.skill = skill;
        }

        @Override
        public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
            return skill.getArmorPenalty();
        }
    }
}
